/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package bmp.dao;

import bmp.common.Constant;
import java.io.Serializable;
import java.sql.Connection;
import java.sql.DriverManager;

/**
 *
 * @author Admin
 */
public class ConnectDB implements Serializable {
    Connection conn;
    public static ConnectDB connectDB;

    
    private ConnectDB(){

    }

    public static ConnectDB getConnectDB(){
	if(connectDB==null)
		connectDB=new ConnectDB();
	return connectDB;
    }

    public void init(){
        try{
            Class.forName(Constant.SETTING_DB_DAO.getString("DRIVER"));
            this.conn=DriverManager.getConnection(Constant.SETTING_DB_DAO.getString("URL")
                ,Constant.SETTING_DB_DAO.getString("USERNAME")
                ,Constant.SETTING_DB_DAO.getString("PASSWORD"));
        }
        catch(Exception e){
            e.printStackTrace();
        }
    }

    public void closeConnect(){
	try{
            if(conn!=null){
		conn.close();
		conn=null;
            }
        }
	catch(Exception e){
            e.printStackTrace();
	}
    }


    public Connection getConnection(){
	try{
            closeConnect();
            init();
	}
	catch(Exception e){
            e.printStackTrace();
	}
        return conn;
    }

}

